package com.result;

import com.entity.PageQuery;

import java.util.List;

public class PageResult<T> {
    private long total;       // 总条数
    private int totalPages;   // 总页数
    private List<T> list;     // 当前页数据

    // 构造方法：传入总条数、分页参数、当前页数据
    public PageResult(long total, PageQuery query, List<T> list) {
        this.total = total;
        this.list = list;
        this.totalPages = (int) Math.ceil((double) total / query.getPageSize());
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageResult{" +
                "total=" + total +
                ", totalPages=" + totalPages +
                ", list=" + list +
                '}';
    }

    public PageResult(long total, int totalPages, List<T> list) {
        this.total = total;
        this.totalPages = totalPages;
        this.list = list;
    }

    public PageResult() {
    }
}